package com.netease.financial.base.share.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.netease.financial.base.web.JSInterface;

import org.json.JSONObject;

public class ShareHolder implements Parcelable {

    public static final Parcelable.Creator<ShareHolder> CREATOR = new Parcelable.Creator<ShareHolder>() {
        @Override
        public ShareHolder createFromParcel(Parcel source) {
            return new ShareHolder(source);
        }

        @Override
        public ShareHolder[] newArray(int size) {
            return new ShareHolder[size];
        }
    };

    @SerializedName(JSInterface.PARAM_JS_SHARE_TITLE)
    public String title = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_DESC)
    public String description = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_IMG_URL)
    public String imageUrl = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_LINK)
    public String webUrl = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_TYPE)
    public String type = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_DATA_URL)
    public String dataUrl = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_EXTRA)
    public String extra = "";

    @SerializedName(JSInterface.PARAM_JS_SHARE_SOURCE_TYPE)
    public String sourceType = "";

    public ShareHolder() {

    }

    public ShareHolder(Parcel parcel) {
        title = parcel.readString();
        description = parcel.readString();
        imageUrl = parcel.readString();
        webUrl = parcel.readString();
        type = parcel.readString();
        extra = parcel.readString();
        dataUrl = parcel.readString();
        sourceType = parcel.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
        dest.writeString(description);
        dest.writeString(imageUrl);
        dest.writeString(webUrl);
        dest.writeString(type);
        dest.writeString(dataUrl);
        dest.writeString(extra);
        dest.writeString(sourceType);
    }

    public static ShareHolder createShareHolderFromJson(JSONObject jsonObject) {
        Gson gson = new Gson();
        return gson.fromJson(jsonObject.toString(), ShareHolder.class);
    }

    @Override
    public String toString() {
        return "ShareHolder{" +
                "title='" + title + '\'' +
                ", description='" + description + '\'' +
                ", imageUrl='" + imageUrl + '\'' +
                ", webUrl='" + webUrl + '\'' +
                ", type='" + type + '\'' +
                ", dataUrl='" + dataUrl + '\'' +
                ", extra='" + extra + '\'' +
                ", sourceType='" + sourceType + '\'' +
                '}';
    }
}